import { Container, Text } from 'pixi.js';
import { Scope } from '../../../typings/traverse';
import { absolutePath, checkNamespace, getGoalData, preResAttributeLoad } from '../../../utils';
interface DealGoal {
    $data: Record<string, any>;
    $watcher: Record<string, Record<string, Array<Function>>>;
}
export function v_text(
    goal: DealGoal,
    container: Container,
    element: Element,
    scope: Scope | undefined
) {
 // v-text
 if (element.hasAttribute("v-text")) {
    const { $data, $watcher } = goal;
    const depName = 'data';
    let _text: string = <string>element.getAttribute("v-text");
    let textPath: string = preResAttributeLoad(_text);
    if (scope) {
      const { item, items, key } = scope;
      let isTextNamespace = checkNamespace(_text, item);
      if (isTextNamespace) {
        textPath = absolutePath(items, item, _text);
      }
    }
    let TextSprite: Text = new Text(getGoalData($data, textPath));
    container.addChild(TextSprite);
    let textFun: Function = function (val: string) {
      TextSprite.text = val;
    };
    if (!$watcher[depName][textPath]) {
      $watcher[depName][textPath] = [];
    }
    $watcher[depName][textPath].push(textFun);
  }
}